package com.ybwh.springboot1.common;

import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

import lombok.Data;

/**
 * 响应base类
 */
@Data
public class Response<T> {
	
	public static final int SUCCEED_CODE = 1;

	public static final int FAIL_CODE = 0;
	
    /**
     * 错误码
     */
    private int flag;

    /**
     * 错误描述
     */
    private String error;

    /**
     * 返回数据
     */
    private T resultMessage;


    public Response() {

    }

    public Response(int flag) {
        this.flag = flag;
    }

    public Response(int flag, String error, T resultMessage) {
        this.flag = flag;
        this.error = error;
        this.resultMessage = resultMessage;
    }
    
    @Override
    public String toString() {
        return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE);
    }
    
    public static <E> Response<E> successResp() {
    	return new Response<E>(SUCCEED_CODE);
    }
    
    public static <E> Response<E> failedResp(String msg) {
    	return new Response<E>(FAIL_CODE,msg,null);
    }


}